package com.yunxi.controller.otd;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.otd.pojo.OtdProduceCalendarVO;
import com.yunxi.otd.service.OtdProduceCalendarDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 生产工作日历 前端控制器
 * </p>
 *
 * @author XUQI
 * @since 2019-07-02
 */
@RestController
@RequestMapping("/admin/otd/pcalendar")
@Api(tags = "OTD:PCALENDAR", description = "生产工作日历接口")
public class OtdProduceCalendarController {

    private static final Logger logger = LoggerFactory.getLogger(OtdProduceCalendarController.class);

    @Autowired
    OtdProduceCalendarDubboService otdProduceCalendarDubboService;

    @GetMapping("/page")
    @ApiOperation(value = "查询列表")
    public ApiResult list(@RequestParam Map<String, Object> queryMap) {
        return ResponseUtil.ok(otdProduceCalendarDubboService.listByMap(queryMap));
    }

    @GetMapping("/week")
    @ApiOperation(value = "周数")
    public ApiResult week(@RequestParam Map<String, Object> queryMap) {
        return ResponseUtil.ok(otdProduceCalendarDubboService.weekListByMap(queryMap));
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存信息")
    public ApiResult save(@RequestBody OtdProduceCalendarVO otdProduceCalendarVO, @CurrentUser LoginInfo loginInfo) {
        otdProduceCalendarDubboService.save(otdProduceCalendarVO, loginInfo);
        return ResponseUtil.ok("success");
    }

    @GetMapping("/not/work")
    @ApiOperation(value = "根据年月查询非工作日")
    public ApiResult queryNoWorkday(String yearMonth) {
        return otdProduceCalendarDubboService.queryNoWorkday(yearMonth);
    }

    @GetMapping("/week/column/head")
    @ApiOperation(value = "根据年月周数列头查询")
    public ApiResult weekColumnHead(String yearMonth) {
        if (StringUtils.isEmpty(yearMonth)) {
            return ResponseUtil.fail(-1, "年月不能为空");
        }
        return otdProduceCalendarDubboService.weekColumnHead(yearMonth);
    }

    @GetMapping("/week/fives/column/head")
    @ApiOperation(value = "根据选定周查询5周列头")
    public ApiResult weekColumnHeadByWeek(String year, String week) {
        if (StringUtils.isEmpty(year)) {
            return ResponseUtil.fail(-1, "年份不能为空");
        }
        if (StringUtils.isEmpty(week)) {
            return ResponseUtil.fail(-1, "周数不能为空");
        }
        week = week.length() == 1 ? "0" + week : week;
        return otdProduceCalendarDubboService.weekColumnHeadByWeek(year, week);
    }

/*@PostMapping("/export")
@ApiOperation(value = "导出excel")
public Object export(@RequestParam Map<String,Object> params) throws Exception {
return ResponseUtil.ok(otdProduceCalendarDubboService.findMapByList(params));
}*/
}
